package vn.sms.lazylove;

import vn.sms.lazylove.database.DataStore;
import vn.sms.lazylove.object.Sms;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class AddSMSActivity extends Activity {

	private Context mContext;
	DataStore mDatastStore;
	EditText edtMessage;
	Button btnAddNew, btnCancel, btnBack, btnEdit;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_addsms);
		mContext = this;
		DataStore.init(mContext);
		mDatastStore = DataStore.getInstance();
		btnBack = (Button) findViewById(R.id.btn_left);
		btnBack.setVisibility(Button.GONE);
		btnEdit = (Button) findViewById(R.id.btn_right);
		btnEdit.setVisibility(Button.GONE);
		TextView txtTitle = (TextView) findViewById(R.id.txt_title);
		txtTitle.setText(getString(R.string.txt_add_sms_patent));
		edtMessage = (EditText) findViewById(R.id.edt_message);
		btnAddNew = (Button) findViewById(R.id.btn_add_new);
		btnCancel = (Button) findViewById(R.id.btn_cancel);
		btnAddNew.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (!edtMessage.getText().toString().equals("")
							&& edtMessage.getText().toString().length() < 160) {
						Sms sms = new Sms(1, edtMessage.getText().toString());
						if (mDatastStore.addSMSPatent(sms)) {
							Toast.makeText(mContext, "Ok!", Toast.LENGTH_SHORT);
							onBackPressed();
						}
					} else {
						Toast.makeText(mContext, "Not empty or message below 160 char.",
								Toast.LENGTH_SHORT);
					}
				} catch (Exception ex) {
					Toast.makeText(mContext, "Not empty!", Toast.LENGTH_SHORT);
				}
			}
		});
		btnCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				onBackPressed();
			}
		});
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

}
